﻿#include <iostream>
#include <vector>
using namespace std;

class Solution
{
public:
    // 518. 零钱兑换 II
    /*int change(int amount, vector<int>& coins)
    {
        int m = coins.size();
        vector<vector<int>> dp(m + 1, vector<int>(amount + 1));
        dp[0][0] = 1;

        for (int i = 1; i <= m; i++)
            for (int j = 0; j <= amount; j++)
            {
                dp[i][j] += dp[i - 1][j];
                if (j >= coins[i - 1])
                    dp[i][j] += dp[i][j - coins[i - 1]];
            }
        return dp[m][amount];
    }*/

    int change(int amount, vector<int>& coins)
    {
        vector<int> dp(amount + 1);
        dp[0] = 1;

        for (int i = 0; i < coins.size(); i++)
            for (int j = coins[i]; j <= amount; j++)
                dp[j] += dp[j - coins[i]];
        return dp[amount];
    }
};

int main()
{
    vector<int> v{ 1,2,5 };
    Solution().change(5, v);

    return 0;
}